﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
/*
 * 接口
 *      接口是用来被class类继承的，规定了继承的class(子类)必须要实现哪些方法，二者订立的'合同'
 *      
 *      
 * 语法：
 *      interface 名字
 *      {
 *          方法;
 *          方法;
 *          .......
 *      }
 *      
 * 命名：接口的名字都是Ixxxx
 */

namespace 继承与多态_接口interface
{
    interface IFireable
    {
        void Fire();

        void MultiFire();
    }
    interface IRunnable
    {
        void Run();
    }
    class MyObject
    {
        public int weight = 0;
        public int width = 0;
        public int height = 0;
    }
    
    //子类可以同时继承父类以及其他接口，但是父类继承需要写在最前方
    class Tank : MyObject, IFireable, IRunnable
    {
        public void Fire()
        {
            Console.WriteLine("dong!");
        }
        public void MultiFire()
        {
            Console.WriteLine("dong! dong! dong!");
        }
        public void Run()
        {
            Console.WriteLine("run");
        }
    }
    internal class Program
    {
        static void Main(string[] args)
        {
            Tank tank = new Tank();
            tank.height = 100;
            tank.Fire();
            tank.MultiFire();
            tank.Run();


            Fire(tank);

            Console.Read();
        }
        static public void Fire(IFireable fireable)
        {
            fireable.Fire();
        }
    }
}
